﻿using MediatR;
using S.Services.SheepMale.Api.Application.Command.MarketCommand;
using S.Services.SheepMale.Domain.PurchaseSales;
using S.Services.SheepMale.Infrastructure;

namespace S.Services.SheepMale.Api.Application.CommandHandler.MarketCommandHandler
{
    public class MarkDelAllCommandHandler : IRequestHandler<MarketDelAllCommand, int>
    {
        private readonly IRepository<EntityMarket> repository;
        public MarkDelAllCommandHandler(IRepository<EntityMarket> repository)
        {
            this.repository = repository;
        }

        public async Task<int> Handle(MarketDelAllCommand request, CancellationToken cancellationToken)
        {
			string[] result = request.markId.Split(',');
            foreach (var item in result)
            {
               await repository.DeleteAsync(int.Parse(item));
			}
            return 1;
        }
    }
}
